using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace OpenSourceHelper.Controls
{
    public partial class FolderBrowse : UserControl
    {
        public event EventHandler FolderSelected;
        public event EventHandler FolderSelecting;


        public FolderBrowse()
        {
            InitializeComponent();
        }

        private string _folder;
        public string Folder
        {
            get
            {
                return _folder;
            }
            set
            {
                _folder = value;
                txtFolder.Text = _folder;
                dlgFolder.SelectedPath = _folder;
            }
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            CallFolderSelecting();

            dlgFolder.ShowDialog();
            Folder = dlgFolder.SelectedPath;

            CallFolderSelected();
        }

        private void CallFolderSelecting()
        {
            if (FolderSelecting != null)
            {
                FolderSelecting(this, new EventArgs());
            }
        }

        private void CallFolderSelected()
        {
            if (FolderSelected != null)
            {
                FolderSelected(this, new EventArgs());
            }
        }

        private void FolderChanged(object sender, EventArgs e)
        {
            CallFolderSelecting();
            Folder = txtFolder.Text;
            CallFolderSelected();
        }
    }
}
